 // 手机号码验证规则
 $.validator.addMethod('isphone', function(value, element, param) {

 	var reg = /^((13|14|15|17|18)[0-9]{1}\d{8})$/;

 	return this.optional(element) || (reg.test(value));

 }, '格式错误');


 // 电话号码验证规则
 $.validator.addMethod('istel', function(value, element, param) {

 	var reg = /^((\d{3,4}-)|\d{3.4}-)?\d{7,8}$/;

 	return this.optional(element) || (reg.test(value));

 }, '格式错误');


 // 手机或者固定电话号码验证规则
 $.validator.addMethod('iscontact', function(value, element, param) {

 	var reg = /^((\d{3,4}-)|\d{3.4}-)?\d{7,8}|((13|14|15|17|18)[0-9]{1}\d{8})$/;

 	return this.optional(element) || (reg.test(value));

 }, '格式错误');


 // 校验传真
 $.validator.addMethod('isfax', function(value, element, param) {

 	var reg = /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/;

 	return this.optional(element) || (reg.test(value));

 }, '传真格式错误');

 // 身份证格式
 // var cP = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
 $.validator.addMethod('isCP', function(value, element, param) {

 	var reg = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;

 	return this.optional(element) || (reg.test(value));

 }, '身份证格式错误');


 // 6-20位字符，区分大小写
 $.validator.addMethod('ispass', function(value, element, param) {

 	var reg = /^[\x21-\x7E]{6,20}$/;

 	return this.optional(element) || (reg.test(value));

 }, '密码格式错误');


 $.validator.addMethod("numberletter", function(value, element) {
 	return this.optional(element) || (/^\w+$/.test(value));
 }, "只能包含数字和英文");



 var aCity = {
 		11: "北京",
 		12: "天津",
 		13: "河北",
 		14: "山西",
 		15: "内蒙古",
 		21: "辽宁",
 		22: "吉林",
 		23: "黑龙江",
 		31: "上海",
 		32: "江苏",
 		33: "浙江",
 		34: "安徽",
 		35: "福建",
 		36: "江西",
 		37: "山东",
 		41: "河南",
 		42: "湖北",
 		43: "湖南",
 		44: "广东",
 		45: "广西",
 		46: "海南",
 		50: "重庆",
 		51: "四川",
 		52: "贵州",
 		53: "云南",
 		54: "西藏",
 		61: "陕西",
 		62: "甘肃",
 		63: "青海",
 		64: "宁夏",
 		65: "新疆",
 		71: "台湾",
 		81: "香港",
 		82: "澳门",
 		91: "国外"
 	},
 	IDmsg = '';

 function isCardID(sId) {
 	var iSum = 0;
 	var info = "";
 	if (!/^\d{17}(\d|x)$/i.test(sId)) return "你输入的身份证长度或格式错误";
 	sId = sId.replace(/x$/i, "a");
 	if (aCity[parseInt(sId.substr(0, 2))] == null) return "你的身份证地区非法";
 	sBirthday = sId.substr(6, 4) + "-" + Number(sId.substr(10, 2)) + "-" + Number(sId.substr(12, 2));
 	var d = new Date(sBirthday.replace(/-/g, "/"));
 	if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate())) return "身份证上的出生日期非法";
 	for (var i = 17; i >= 0; i--) iSum += (Math.pow(2, i) % 11) * parseInt(sId.charAt(17 - i), 11);
 	if (iSum % 11 != 1) return "你输入的身份证号非法";
 	//aCity[parseInt(sId.substr(0,2))]+","+sBirthday+","+(sId.substr(16,1)%2?"男":"女");//此次还可以判断出输入的身份证号的人性别
 	return true;
 }

 $.validator.addMethod('isID', function(value, element, param) {

 	var status = isCardID(value);

 	status = typeof status === 'string' ? false : true;

 	return this.optional(element) || status;

 }, '身份证非法');

 $.validator.addMethod("integer", function(value, element) {
 	msg = isCardID(value) ? '身份证格式错误' : isCardID(value);
 	return this.optional(element) || (/^([1-9][0-9]*)$/.test(value));
 }, "只能是整数数字");

// 非0正整数
  $.validator.addMethod('isnum', function(value, element, param) {

 	var reg = /^[1-9]\d*$/;

 	return this.optional(element) || (reg.test(value));

 }, '只能是非0正整数');

  // 可为0正整数
  $.validator.addMethod('isnumber', function(value, element, param) {

 	var reg = /^([1-9]\d*|[0]{1,1})$/;

 	return this.optional(element) || (reg.test(value));

 }, '只能是正整数');

    // 可负为0整数
  $.validator.addMethod('isallnum', function(value, element, param) {

 	var reg = /^(0|[1-9][0-9]*|-[1-9][0-9]*)$/;

 	return this.optional(element) || (reg.test(value));

 }, '只能是整数');